package com.mindcoord.handbook.service.impl;

import com.mindcoord.handbook.dao.ClazzMapper;
import com.mindcoord.handbook.pojo.Clazz;
import com.mindcoord.handbook.common.Result;
import com.mindcoord.handbook.service.ClazzService;

public class ClazzServiceImpl implements ClazzService {

    private ClazzMapper clazzMapper;

    public void setClazzMapper(ClazzMapper clazzMapper) {
        this.clazzMapper = clazzMapper;
    }

    @Override
    public Result listClazzs() {
        Result result;
        try {
            result = Result.success(clazzMapper.listClazzs());
        } catch (Exception e) {
            result = Result.fail("查询失败");
        }
        return result;
    }

    @Override
    public Result getClazzById(Integer id) {
        Result result;
        try {
            result = Result.success(clazzMapper.getClazzById(id));
        } catch (Exception e) {
            result = Result.fail("查询失败");
        }
        return result;
    }

    @Override
    public Result insertClazz(Clazz clazz) {
        Result result;
        try {
            Boolean b = clazzMapper.insertClazz(clazz);
            result = b ? Result.success(null) : Result.fail("插入失败");
        } catch (Exception e) {
            result = Result.fail("插入失败");
        }
        return result;
    }

    @Override
    public Result deleteClazzById(Integer id) {
        Result result;
        try {
            Boolean b = clazzMapper.deleteClazzById(id);
            result = b ? Result.success(null) : Result.fail("删除失败");
        } catch (Exception e) {
            result = Result.fail("删除失败");
        }
        return result;
    }

    @Override
    public Result updateClazz(Clazz clazz) {
        Result result;
        try {
            Boolean b = clazzMapper.updateClazz(clazz);
            result = b ? Result.success(null) : Result.fail("更新失败");
        } catch (Exception e) {
            result = Result.fail("更新失败");
        }
        return result;
    }

}
